package org.dreamwork.cai.proxy;

import net.sf.cglib.proxy.Enhancer;
import org.dreamwork.cai.srf.ServiceRouteItem;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 11-11-17
 * Time: 下午5:04
 */
public class DynamicProxyFactory {
    private static final DynamicProxyFilter filter = new DynamicProxyFilter ();

    public static Object getProxy (ServiceRouteItem sri, Class<?> superClass, Class<?>... interfaceClasses) {
        DynamicProxyCallback callback = new DynamicProxyCallback (sri);

        Enhancer enhancer = new Enhancer ();
        enhancer.setSuperclass (superClass);
        enhancer.setInterfaces (interfaceClasses);
        enhancer.setCallback (callback);
        enhancer.setCallbackFilter (filter);

        return enhancer.create ();
    }
}
